package com.siwei.mes.entity.experiment.flyAsk;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 粉煤灰-活性指数
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FlyAskHdzs {
    @ApiModelProperty(value = "活性指数信息")
    private List<FlyAskHdzs.HxzsInfoList> hxzsInfoList = Collections.singletonList(new FlyAskHdzs.HxzsInfoList());

    @Data
    @Accessors(chain = true)
    @ApiModel("活性指数信息")
    public static class HxzsInfoList {
        @ApiModelProperty(value = "检测日期")
        private String jcrq ="";
        @ApiModelProperty(value = "单项结论")//1
        private String dxjl ="";
        @ApiModelProperty(value = "活性指数")//1
        private String hxzs ="";
        @ApiModelProperty(value = "实验胶砂百分比")
        private String syjsbfb ="";
        @ApiModelProperty(value = "对比胶砂百分比")
        private String dbjsbfb ="";
        @ApiModelProperty(value = "实验胶砂结论")
        private String syjsjl ="";
        @ApiModelProperty(value = "对比胶砂结论")
        private String dbjsjl ="";
        @ApiModelProperty(value = "对比胶砂强度信息")
        private Dbqd dbjsdbqd = new Dbqd();
        @ApiModelProperty(value = "实验胶砂强度信息")
        private Dbqd syjskdbqd = new Dbqd();
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("活性指数强度信息")
    public static class Dbqd {
        @ApiModelProperty(value = "强度1")
        private String qd1 ="";
        @ApiModelProperty(value = "强度2")
        private String qd2 ="";
        @ApiModelProperty(value = "强度3")
        private String qd3 ="";
        @ApiModelProperty(value = "强度4")
        private String qd4 ="";
        @ApiModelProperty(value = "强度5")
        private String qd5 ="";
        @ApiModelProperty(value = "强度6")
        private String qd6 ="";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FlyAskHdzs entity = new FlyAskHdzs();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FlyAskHdzs.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FlyAskHdzs.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FlyAskHdzs entity = JsonUtils.getObject(objJson, FlyAskHdzs.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        List<FlyAskHdzs.HxzsInfoList> hxzsInfoList = entity.getHxzsInfoList();
        for(HxzsInfoList hxzsInfo:hxzsInfoList){
            if (StringUtils.isBlank(hxzsInfo.getHxzs()) || "null".equals(hxzsInfo.getHxzs())) {
                return "存在必检项(" + name + ")未检测，请先检测！";
            }
            /*if (StringUtils.isBlank(hxzsInfo.getDxjl()) || "null".equals(hxzsInfo.getDxjl())) {
                return "存在必检项(" + name + ")未检测，请先检测！";
            }*/
        }
        return null;
    }
}
